<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="链" prop="coin">
        <MainCoin @change="onChainChange" :coin.sync="queryParams.coin" type="0" size="small"/>
      </el-form-item>
      <el-form-item label="商户号" prop="memberId">
        <el-input
          v-model="queryParams.memberId"
          placeholder="请输入商户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="币种标识" prop="symbol">
        <el-input
          v-model="queryParams.symbol"
          placeholder="请输入币种标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.addressTo"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="状态" size="small" :clearable="true">
            <el-option
              v-for="(v, k) in statusMap"
              :key="k"
              :label="v"
              :value="k"
            />
          </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"></el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="ID" align="center" prop="id" width="80"/>
      <el-table-column label="商户号" align="center" prop="memberId" width="80"/>
      <el-table-column label="币种ID" align="center" prop="coinId" width="80"/>
      <el-table-column label="币种标识" align="center" prop="coinSymbol" />
      <el-table-column label="归集类型" align="center" prop="type">
        <template slot-scope="scope">
          {{ typeMap[scope.row.type] }}
        </template>
      </el-table-column>
      <el-table-column label="归集地址" align="center" prop="address" />
      <el-table-column label="收款地址" align="center" prop="toAddress" />
      <el-table-column label="归集金额" align="center" prop="amount" />
      <el-table-column label="手续费" align="center" prop="fee" />
      <el-table-column label="交易ID" align="center" prop="txId">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleViewAddress(scope.row.txId, '交易ID')" v-show="scope.row.status == 1 || scope.row.status == 2">查看交易ID</el-button>
          <el-button size="mini" type="text" @click="handleViewAddress(scope.row.txId, '交易ID')" v-show="scope.row.status == 3">查看失败原因</el-button>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ statusMap[scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedDate) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />

    <el-dialog :title="dialogAddress.title" :visible.sync="dialogAddress.visible" width="30%">
      <span>{{ dialogAddress.value }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogAddress.visible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import { listCollectAddress  } from "@/api/aipay/wallet";
export default {
  name: "AddressBalance",
  data() {
    return {
      dialogAddress: {
        visible: false,
        title: '',
        value: ''
      },
      coins: [],
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //表格数据
      postList: [],
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      activeName: "public",
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {},
      statusMap: {
        0: '待归集',
        1: '确认中',
        2: '已归集',
        3: '归集失败'
      },
      typeMap: {
        0: '普通地址',
        1: '热钱包'
      }
    };
  },
  watch: {
    'queryParams.coin': {
      handler(val) {
        if (val) {
        } else {
        }
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    //this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listCollectAddress(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    onChainChange(value){
      console.log(value)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleViewAddress(value, title){
      this.dialogAddress.title = title
      this.dialogAddress.value = value
      this.dialogAddress.visible = true
    },
  }
};
</script>
